﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class TranslateDataTables : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");
            else
            {
                GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
                OnlineUser ou = (OnlineUser)Session["User"];
                if ((ou.UserAccessLevel != ("5")) && (ou.UserAccessLevel != ("3")))
                {
                    Response.Redirect("~/GeneralMessage.aspx?MessageString=" + ou.UserAccessLevel);
                }
                
                if (ou.TeamId == "Null")
                    Response.Redirect("~/GeneralMessage.aspx?MessageString=274ggdizz5!lk");

                string Language = GND.ReadNivdalIntData("UserId", "Nivdal_GetUserTranslateLanguage", ou.UserId);
                if ((Language == null) || (Language == "0"))
                    Response.Redirect("GeneralMessage.aspx?MessageString=k882m299nnqmhtsd");
                else if (Language == "2")
                    Response.Redirect("TranslateEnglish.aspx");
                else
                {
                    this.LanguageIdHiddenField.Value = Language;
                }
            }
        }

        protected void DataAggressivnessValuesSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string AggressivnessName;
            foreach (GridViewRow Item in DataAggressivnessValuesGridView.Rows)
            {
                id = (Item.FindControl("DataAggressivnessIdHiddenField") as HiddenField).Value;
                AggressivnessName = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "AggressivnessName", "Nivdal_UpdateNivdal_DataAggressivnessValues", id, Language, AggressivnessName);
                DataAggressivnessValuesUpdatedLabel.Visible = true;
            }
            DataAggressivnessValuesGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataAttitudeValuesSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string AttitudeName;
            foreach (GridViewRow Item in DataAttitudeValuesGridView.Rows)
            {
                id = (Item.FindControl("DataAttitudeValuesIdHiddenField") as HiddenField).Value;
                AttitudeName = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "AttitudeName", "Nivdal_UpdateNivdal_DataAttitudeValues", id, Language, AttitudeName);
                DataAttitudeValuesUpdatedLabel.Visible = true;
            }
            DataAttitudeValuesGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataPlayerAttributeNameSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string PlayerAttribute;
            foreach (GridViewRow Item in DataPlayerAttributeNameGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                PlayerAttribute = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Name", "Nivdal_UpdateNivdal_DataPlayerAttributeName", id, Language, PlayerAttribute);
                DataPlayerAttributeNameUpdatedLabel.Visible = true;
            }
            DataPlayerAttributeNameGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataPlayerInstructionsSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string InstructionName;
            foreach (GridViewRow Item in DataPlayerInstructionsGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                InstructionName = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "InstructionName", "Nivdal_UpdateNivdal_DataPlayerInstructions", id, Language, InstructionName);
                DataPlayerInstructionsUpdatedLabel.Visible = true;
            }
            DataPlayerInstructionsGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataPlayerPositionsSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string PositionName;
            foreach (GridViewRow Item in DataPlayerPositionsGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                PositionName = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "PositionName", "Nivdal_UpdateNivdal_DataPlayerPositions", id, Language, PositionName);
                DataPlayerPositionsUpdatedLabel.Visible = true;
            }
            DataPlayerPositionsGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataPossessionDirValuesSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string PossessionString;
            foreach (GridViewRow Item in DataPossessionDirValuesGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                PossessionString = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "PossessionString", "Nivdal_UpdateNivdal_DataPossessionDirValues", id, Language, PossessionString);
                DataPossessionDirValuesUpdatedLabel.Visible = true;
            }
            DataPossessionDirValuesGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataPreferredActionsSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string ActionName;
            foreach (GridViewRow Item in DataPreferredActionsGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                ActionName = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "ActionName", "Nivdal_UpdateNivdal_DataPreferredActions", id, Language, ActionName);
                DataPreferredActionsUpdatedLabel.Visible = true;
            }
            DataPreferredActionsGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataRedCardStatusSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string RedCardStatus;
            foreach (GridViewRow Item in DataRedCardStatusGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                RedCardStatus = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "RedCardStatus", "Nivdal_UpdateNivdal_DataRedCardStatus", id, Language, RedCardStatus);
                DataRedCardStatusUpdatedLabel.Visible = true;
            }
            DataRedCardStatusGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataSubstitutionGoalsConditionsSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Condition;
            foreach (GridViewRow Item in DataSubstitutionGoalsConditionsGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Condition = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Condition", "Nivdal_UpdateNivdal_DataSubstitutionGoalsConditions", id, Language, Condition);
                DataSubstitutionGoalsConditionsUpdatedLabel.Visible = true;
            }
            DataSubstitutionGoalsConditionsGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataUserPunishmentsOptionsSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Description;
            foreach (GridViewRow Item in DataUserPunishmentsOptionsGridView.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Description = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Description", "Nivdal_UpdateNivdal_DataUserPunishmentsOptions", id, Language, Description);
                DataUserPunishmentsOptionsUpdatedLabel.Visible = true;
            }
            DataUserPunishmentsOptionsGridView.DataBind();
            StatusFormView.DataBind();
        }

        protected void DataWeatherSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Description;
            foreach (GridViewRow Item in WeatherTranslateGridVeiw.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Description = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Description", "Nivdal_UpdateNivdal_DataWeatherValues", id, Language, Description);
                WeatherUpdatedLabel.Visible = true;
            }
            WeatherTranslateGridVeiw.DataBind();
            StatusFormView.DataBind();
        }

        protected void TournamentTypesSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Description;
            foreach (GridViewRow Item in TournamentTypesGridveiew.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Description = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Description", "Nivdal_UpdateNivdal_DataTournamentTypes", id, Language, Description);
                TournamentTypeUpdatedLabel.Visible = true;
            }
            StatusFormView.DataBind();
        }

        protected void TournamentExecutionStatusSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Description;
            foreach (GridViewRow Item in TournamentExecutionStatusGridveiew.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Description = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Description", "Nivdal_UpdateNivdal_DataTournamentExecutionStatus", id, Language, Description);
                TournamentExecutionStatusUpdatedLabel.Visible = true;
            }
            StatusFormView.DataBind();
        }
        protected void TournamentApprovalStatusSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Description;
            foreach (GridViewRow Item in TournamentApprovalStatusGridveiew.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Description = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Description", "Nivdal_UpdateNivdal_DataTournamentApprovalStatus", id, Language, Description);
                TournamentApprovalStatusUpdatedLabel.Visible = true;
            }
            StatusFormView.DataBind();
        }
        protected void TournamentStageTypeSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Description;
            foreach (GridViewRow Item in TournamentStageTypeGridveiew.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Description = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Description", "Nivdal_UpdateNivdal_DataTournamentStageType", id, Language, Description);
                TournamentStageTypeUpdatedLabel.Visible = true;
            }
            StatusFormView.DataBind();
        }

        protected void UserTournamentRoleSubmit(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string id;
            string Language = LanguageIdHiddenField.Value;
            string Description;
            foreach (GridViewRow Item in UserTournamentRoleGridveiew.Rows)
            {
                id = (Item.FindControl("IdHiddenField") as HiddenField).Value;
                Description = (Item.FindControl("TranslationTextBox") as TextBox).Text;
                GND.ReadNivdalStringData("Id", "Language", "Description", "Nivdal_UpdateNivdal_DataUserTournamentRole", id, Language, Description);
                UserTournamentRoleUpdatedLabel.Visible = true;
            }
            StatusFormView.DataBind();
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}